package com.app.piemoment;

import java.text.SimpleDateFormat;
import java.util.Date;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.app.piemoment.entity.OppositeInfo;


public class PairDetailActivity extends BaseActivity implements OnClickListener{

	private TextView username_text;
	private TextView birth_text;
	private TextView hight_text;
	private TextView bodily_text;
	private TextView school_text;
	private TextView education_text;
	private TextView occupation_text;
	private TextView birth_place_text;
	private TextView constellation_text;
	private TextView age_text;
	
	public PairDetailActivity() {
		mainViewId = R.layout.detail_activity;
	}
	
	@Override
	protected void initMainView() {
		initTitle(R.drawable.btn_back_bg,R.string.oppt_title, 0,0);
		constellation_text = (TextView)findViewById(R.id.constellation_text);
		age_text = (TextView)findViewById(R.id.age_text);
		
		username_text = (TextView)findViewById(R.id.username_text);
		birth_text =(TextView)findViewById(R.id.birthday_text);
		hight_text =(TextView)findViewById(R.id.hight_text);
		bodily_text =(TextView)findViewById(R.id.bodily_text);
		school_text =(TextView)findViewById(R.id.school_text);
		education_text =(TextView)findViewById(R.id.education_text);
		birth_place_text =(TextView)findViewById(R.id.birth_place_text);
		occupation_text =(TextView)findViewById(R.id.occupation_text);
		//TODO 部分text显示
	}


	@Override
	protected void registerMainViewEvent() {
		
	}


	@Override
	protected void processMainView() {
		constellation_text.setVisibility(View.INVISIBLE);
		OppositeInfo info = getIntent().getParcelableExtra("matchInfo");
		if(info!=null) {
			updateInfo(info);
		}
	}

	private void updateInfo(OppositeInfo target_info) {
		if(target_info!=null) {
			age_text.setText(getAge(target_info.getBirthday()));//TODO 男性女性图标改变
			username_text.setText(target_info.getNickname());
			birth_text.setText(target_info.getBirthday());
			hight_text.setText(target_info.getHeight()+"");
			bodily_text.setText(target_info.getWeight()+"");
			school_text.setText(target_info.getSchool());
			education_text.setText(target_info.getDegree());
			birth_place_text.setText(target_info.getBirthPlace()!=null?target_info.getBirthPlace().getArea():"");
			occupation_text.setText(target_info.getOccupation());
		}
		
	}
	

	private String getAge(String birthday) {
		int age = 0;
		long timeMillis = System.currentTimeMillis();
		SimpleDateFormat format = new SimpleDateFormat("yyyy-mm-dd");
		String current = format.format(new Date(timeMillis));
		String[] split = birthday.split("-");
		String[] split1 = current.split("-");
		if(Integer.parseInt(split1[1])>Integer.parseInt(split[1])) {
			age = Integer.parseInt(split1[0]) - Integer.parseInt(split[0]);
		}else {
			age = Integer.parseInt(split1[0]) - Integer.parseInt(split[0]) - 1;
		}
		return age+"";
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_left:
			super.onBackPressed();
			break;
		default:
			break;
		}
	}


}
